# Maintainer: Andrew Crerar <crerar@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Iwan Timmer <irtimmer@gmail.com>
# Contributor: Vincent Demeester <vincent@sbr.io>
# Contributor: Josh VanderLinden <arch@cloudlery.com>

pkgname=docker-compose
pkgver=2.23.1
pkgrel=1
pkgdesc="Fast, isolated development environments using Docker"
arch=('loong64' 'x86_64')
url="https://www.docker.com/"
license=("Apache")
makedepends=('go')
checkdepends=('docker')
source=("$pkgname-$pkgver.tar.gz::https://github.com/docker/compose/archive/v$pkgver.tar.gz")
b2sums=('a9f4e49fe99b8f0f2af48e805cc1a7dc56e0964b09dec4cf7c63d3c7b20f4c1fc3e8104d321ad7abc0e1e54d76a10be096363082eb50d68b39782e53aee58498')

build() {
  cd "compose-$pkgver"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -ldflags=-X=github.com/docker/compose/v2/internal.Version=${pkgver} -mod=readonly -modcacherw"
  CGO_ENABLED=0 go build -trimpath -tags "e2e,kube" -o compose ./cmd
}

check(){
  cd "compose-$pkgver"
  rm pkg/compose/ps_test.go
  CGO_ENABLED=0 go test -tags "e2e,kube" -v $(go list -tags "e2e,kube" ./... | grep -vE 'e2e')
}

package() {
  cd "compose-$pkgver"
  install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
  install -Dm755 compose "$pkgdir"/usr/lib/docker/cli-plugins/docker-compose
  install -d "$pkgdir/usr/bin"
  ln -sf /usr/lib/docker/cli-plugins/docker-compose "$pkgdir/usr/bin/docker-compose"
}
